package lbframework.bean.tabbedPane;

import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import javax.swing.AbstractAction;
import javax.swing.JComponent;
import javax.swing.JTabbedPane;
import javax.swing.KeyStroke;
import lbframework.bean.internalFrame.LBInternalFrame;

public class LBTabbedPane extends JTabbedPane {

    private LBInternalFrame internalFrame = null;

    public LBTabbedPane() {
        initComponents();
    }

    public void setAtalho(LBInternalFrame i_internalFrame) {
        try {
            internalFrame = i_internalFrame;

            internalFrame.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, InputEvent.ALT_DOWN_MASK), "abaProximo");
            internalFrame.getActionMap().put("abaProximo", new AbstractAction("abaProximo") {

                @Override
                public void actionPerformed(ActionEvent evt) {
                    if (getSelectedIndex() < getTabCount() - 1) {
                        setSelectedIndex(getSelectedIndex() + 1);
                    }
                }
            });

            internalFrame.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, InputEvent.ALT_DOWN_MASK), "abaAnterior");
            internalFrame.getActionMap().put("abaAnterior", new AbstractAction("abaAnterior") {

                @Override
                public void actionPerformed(ActionEvent evt) {
                    if (getSelectedIndex() > 0) {
                        setSelectedIndex(getSelectedIndex() - 1);
                    }
                }
            });
        } catch (Exception ex) {
        }
    }

    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                formComponentShown(evt);
            }
        });
        addContainerListener(new java.awt.event.ContainerAdapter() {
            public void componentAdded(java.awt.event.ContainerEvent evt) {
                formComponentAdded(evt);
            }
        });
    }// </editor-fold>//GEN-END:initComponents

    private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
    }//GEN-LAST:event_formComponentShown

    private void formComponentAdded(java.awt.event.ContainerEvent evt) {//GEN-FIRST:event_formComponentAdded
    }//GEN-LAST:event_formComponentAdded
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
